﻿#region
using System;
using System.Windows;
using System.Windows.Forms;
using Y2M2.Properties;
using UserControl = System.Windows.Controls.UserControl;

#endregion

namespace Y2M2
{
    public partial class SettingControl : UserControl
    {
        public SettingControl()
        {
            InitializeComponent();
        }

        private void rdbVideoOnly_Checked(object sender, RoutedEventArgs e)
        {
            Settings.Default.AudioOnly = false;
        }

        private void rdbAudioOnly_Checked(object sender, RoutedEventArgs e)
        {
            Settings.Default.AudioOnly = true;
        }

        private void btnBrowse_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new FolderBrowserDialog();

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                txtBrowse.Text = dialog.SelectedPath;
                Settings.Default.DownloadRoot = txtBrowse.Text;
            }
        }

        private void SettingControl_Loaded(object sender, RoutedEventArgs e)
        {
            txtBrowse.Text = Settings.Default.DownloadRoot;
        }

        private void chkTopMost_Checked(object sender, RoutedEventArgs e)
        {
            OnTopMostChanged(chkTopMost.IsChecked.HasValue && chkTopMost.IsChecked.Value);
        }

        #region TopMostChanged event things for C# 3.0
        public event EventHandler<TopMostChangedEventArgs> TopMostChanged;

        protected virtual void OnTopMostChanged(TopMostChangedEventArgs e)
        {
            if (TopMostChanged != null)
                TopMostChanged(this, e);
        }

        protected virtual void OnTopMostChanged(bool hasChecked)
        {
            OnTopMostChanged(new TopMostChangedEventArgs(hasChecked));
        }

        protected virtual TopMostChangedEventArgs OnTopMostChangedWithReturn(bool hasChecked)
        {
            TopMostChangedEventArgs args = new TopMostChangedEventArgs(hasChecked);
            OnTopMostChanged(args);

            return args;
        }

        public class TopMostChangedEventArgs : EventArgs
        {
            public bool HasChecked { get; set; }

            public TopMostChangedEventArgs()
            {
            }

            public TopMostChangedEventArgs(bool hasChecked)
            {
                HasChecked = hasChecked;
            }
        }
        #endregion
    }
}